﻿package com.wandian.util
{
	import com.wandian.data.GameData;

	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**   
	* @author long
	* @QQ 108232706
	* @version 1.0   
	*/   
	public class RadioRoom extends MovieClip
	{
		private var _arrRadio:Array;
		public var _radioId:int=0;
		private var _isNull:Boolean;
		private var _recordData:Array;

		public function RadioRoom(arrRadio:Array):void
		{
			var mcRadio:MovieClip=null;
			this._arrRadio=arrRadio;
			this._recordData=[];
			var index:int=0;
			while (index < this._arrRadio.length)
			{

				this._recordData[index]=0;
				mcRadio=this._arrRadio[index] as MovieClip;
				mcRadio.mouseChildren=false;
				mcRadio.buttonMode=true;
				mcRadio.id=index;
				mcRadio.addEventListener(MouseEvent.CLICK, this.clickRadioHandler);
				index=index + 1;
			}
			return;
		} 

		private function setRadioSelect():void
		{
			if (this._recordData[0] == 1)
			{
				if (this._recordData[1] == 1)
				{
					this._radioId=GameData.RADIO3;
				}
				else
				{
					this._radioId=GameData.RADIO1;
				}
			}
			else if (this._recordData[1] == 1)
			{
				this._radioId=GameData.RADIO2;
			}
			else
			{
				this._radioId=0;
			}
			this.dispatchEvent(new Event(Event.CHANGE));
			return;
		} 

		private function clickRadioHandler(event:MouseEvent):void
		{
			var mcRadio:MovieClip=event.currentTarget as MovieClip;
			if (this._recordData[mcRadio.id] == 1)
			{
				this._recordData[mcRadio.id]=0;
				mcRadio.gotoAndStop("no");
			}
			else
			{
				this._recordData[mcRadio.id]=1;
				mcRadio.gotoAndStop("yes");
			}
			this.setRadioSelect();
			return;
		} 

	}
}
